package com.zhishu.system.service;

import com.zhishu.system.model.Task;
import org.apache.log4j.Logger;
import org.nutz.dao.Dao;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Component
public class TaskService {
    private static final Logger LOGGER = Logger.getLogger(TaskService.class);
    @Resource
    private Dao taskDao;

    public boolean addTask(String requestId, String url, String uuid, String userId) {
        boolean result = false;

        Task task = new Task();
        task.setCreate_time(new Date());
        task.setUuid(uuid);
        task.setUser_id(Long.parseLong(userId));
        task.setUrl(url);
        task.setRequest_id(requestId);
        task.setStatus(0);

        try {
            taskDao.insert(task);
            result = true;
            LOGGER.info("插入task成功,requestId:" + requestId + ",userId:" + userId);
        } catch (Exception e) {
            LOGGER.warn("插入task异常", e);
        }

        return result;
    }

}
